package config

import (
	"context"
	"github.com/go-redis/redis/v8"
	"tcp_server/src/common_util"
)

var Redis *redis.Client

func init() {
	Redis = redis.NewClient(&redis.Options{
		Addr:         RedisAddress,
		Password:     RedisPassword,
		DB:           0,
		PoolSize:     RedisPoolSize,
		MinIdleConns: RedisMinIdleConn,
		DialTimeout:  RedisDialTimeout,
		ReadTimeout:  RedisReadTimeout,
		WriteTimeout: RedisWriteTimeout,
	})

	// 测试连接
	_, err := Redis.Ping(context.Background()).Result()
	if err != nil {
		common_util.ErrorLogger.Printf("连接Redis失败: %v", err)
	} else {
		common_util.InfoLogger.Printf("连接Redis成功")
	}
}
